public class SequenceStack<T> {
    final  int MAX_CAPACITY = 10;
    private  T[] stackArray;
    private int top;
    public  SequenceStack(){
        stackArray = (T[]) new  Object[MAX_CAPACITY];
        top = -1;
    }
    public  SequenceStack(int n){
        top = -1;
        stackArray = (T[]) new  Object[n];
    }
    public void  push(T obj){
        if(top == stackArray.length -1){
            T[] p =(T[]) new  Object[top*2+2];
            for (int i = 0; i <= top; i++) {
                p[i] = stackArray[i];
            }
            stackArray = p;
        }
        top++;
        stackArray[top] = obj;
    }

    public  T pop(){
        if(top==-1){
            System.out.println("数据栈已空，无法删除元素");
            return null;
        }
        top--;
        return stackArray[top+1];
    }
    public  T getHead(){
        return stackArray[top];
    }
    public  boolean isEmpty(){return  top == -1;}
    public  int size(){
        return  top+1;
    }
    public  void  nextOrder(){
        for (int i = top; i <= 0; i--) {
            System.out.print(stackArray[i]+"\t");
        }
        System.out.println();
    }
    public  void  clear(){
        top = -1;
    }
}
